package com.atguigu.flink.day03;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.connector.source.util.ratelimit.RateLimiterStrategy;
import org.apache.flink.connector.datagen.source.DataGeneratorSource;
import org.apache.flink.connector.datagen.source.GeneratorFunction;
import org.apache.flink.connector.kafka.source.KafkaSource;
import org.apache.flink.connector.kafka.source.enumerator.initializer.OffsetsInitializer;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Felix
 * @date 2023/12/2
 * 该案例演示了源算子--数据生成器
 */
public class Flink05_source_dataGen {
    public static void main(String[] args) throws Exception {
        //TODO 指定流处理环境
        StreamExecutionEnvironment env
            = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(2);

        //TODO 生成数据
        DataGeneratorSource<String> generatorSource = new DataGeneratorSource<>(
            new GeneratorFunction<Long, String>() {
                @Override
                public String map(Long value) throws Exception {
                    return "数据:" + value;
                }
            },
            100,
            RateLimiterStrategy.perSecond(2),
            TypeInformation.of(String.class)
        );

        env
            .fromSource(generatorSource,WatermarkStrategy.noWatermarks(),"data_source")
            .print();
        //TODO 提交
        env.execute();
    }

}
